//初始化数据库
const db=wx.cloud.database();
const banner=db.collection("banner");
const menu=db.collection("menu");
const recommend=db.collection("recommend");
const guessLove=db.collection("guessLove");
const userDB = db.collection("userDB");

Page({

  /**
   * 页面的初始数据
   */
  data: {
   active:0,
   banner:[],
   menu:[],
   recommend:[],
   guessLove:[]
  },
  
  onShow() {
    this.getTabBar().init();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

   banner.get().then(res=>{
     this.setData({
       banner:res.data
     })
   }),
   menu.get().then(res=>{
     //console.log(res.data)
    this.setData({
      menu:res.data
    })
   }),

    recommend.get().then(res=>{
      //console.log(res.data)
      this.setData({
        recommend:res.data
      })
    }),
    guessLove.get().then(res=>{
      //console.log(res.data);
      this.setData({
        guessLove:res.data
      })
    })

  },
  onTapToStore:function(event){
    wx.navigateTo({ 
      url: '../store/store'
    })
  },
  onTapToGoods:function(event){
    var goodname = event.currentTarget.dataset.goodname;
    var goodsId = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../detail/detail?goodsId=' + goodsId +'&tapDBName='+'recommend'+'&goodname='+goodname
    })
  },
  onTapToLoveGoods:function(event){
    var goodname = event.currentTarget.dataset.goodname;
    var goodsId = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../detail/detail?goodsId=' + goodsId +'&tapDBName='+'guessLove'+'&goodname='+goodname
    })
  }
 
})

